{{!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!

This is a top level C++ file that generates an implementation of the C++ clients
interface. Each client method adds a callback to run in the C++ EventBase IO
thread that will pass data to the cython callback.

}}
{{> common/AutoGeneratedC}}

#include <{{program:includePrefix}}gen-py3/{{program:name}}/clients_wrapper.h>

{{#program:cppNamespaces}}namespace {{value}} {
{{/program:cppNamespaces}}


{{#program:services}}
{{#service:functions}}{{^function:returns_sink?}}
folly::Future<{{#function:returnType}}{{> clients/CppReturnType}}{{/function:returnType}}>
{{service:name}}ClientWrapper::{{function:name}}(
    apache::thrift::RpcOptions& rpcOptions{{#function:args}},
    {{#field:type}}{{> types/CppValueType}}{{/field:type}} arg_{{field:py_name}}{{/function:args}}) {
  folly::Promise<{{#function:returnType}}{{> clients/CppReturnType}}{{/function:returnType}}> _promise;
  auto _future = _promise.getFuture();
  auto* client = static_cast<::{{#service:cppNamespaces}}{{value}}::{{/service:cppNamespaces}}{{service:name}}AsyncClient*>(async_client_.get());
  {{^function:oneway?}}
  auto callback = std::make_unique<::thrift::py3::FutureCallback<{{#function:returnType}}{{> clients/CppReturnType}}{{/function:returnType}}>>(
    std::move(_promise), rpcOptions, client->recv_wrapped_{{function:name}}, channel_);
  {{/function:oneway?}}
  {{#function:oneway?}}
  {{! oneway functions have no recv they are special cased}}
  auto callback = std::make_unique<::apache::thrift::OneWayFutureCallback>(
    std::move(_promise), channel_);
  {{/function:oneway?}}
  client->{{function:name}}(
    rpcOptions,
    std::move(callback){{#function:args}},
    arg_{{field:py_name}}{{/function:args}}
  );
  return _future;
}

{{/function:returns_sink?}}{{/service:functions}}
{{/program:services}}{{!
}}{{#program:cppNamespaces}}} // namespace {{value}}
{{/program:cppNamespaces}}
